﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Stock.Properties;
using Stock.Models.Classes;

namespace Stock
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            label2.Visible = false;
            MultiplicadorTxt.Text = Settings.Default["multiplicador"].ToString();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void GuardarmultBtn_Click(object sender, EventArgs e)
        {
            decimal mul = Decimal.Parse(Herramientas.PuntoToComa(MultiplicadorTxt.Text));
            Settings.Default["multiplicador"] = mul;
            Settings.Default.Save();
            Repository repository = Repository.Instance;
            List<Product> products = (List<Product>)repository.Session.CreateCriteria<Product>().List<Product>();
            foreach (Product pro in products)
            {
                decimal multiplicador = (decimal)Settings.Default["multiplicador"];
                pro.ListPrice = pro.CostPrice+pro.CostPrice * (multiplicador/100);
            }
            repository.SaveAll<Product>(products);
            label2.Text = "Se Actualizo Correctamente";
            label2.Visible=true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            decimal mul = Decimal.Parse(Herramientas.PuntoToComa(MultiplicadorTxt.Text));
            Settings.Default["multiplicador"] = mul;
            Settings.Default.Save();
            label2.Text = "Se Guardo Correctamente";
            label2.Visible = true;
        }
    }
}
